<template>
	<view class="swiper-view">
		<view v-if="title!==''" class="view-head">
			<text class="view-title">{{title}}</text>
			<view class="view-tab">
				<scroll-view scroll-x="true">
					<view class="scroll">
						<view :class="(index === nowTab) ? 'tab-item_select' : 'tab-item'" v-for="(item,index) in tabTexts" :key="index"
						 @click="checkTab(index)">
							{{item}}
						</view>
					</view>
				</scroll-view>
			</view>
		</view>

		<view v-if="title===''" class="view-head-no_title">
			<view class="view-tab-no_title">
				<scroll-view scroll-x="true">
					<view class="scroll">
						<view :class="(index === nowTab) ? 'tab-item_select' : 'tab-item'" v-for="(item,index) in tabTexts" :key="index"
						 @click="checkTab(index)">
							{{item}}
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<swiper class="view-body" :current="nowTab" @change="swiper">
			<swiper-item class="item" v-for="item in tabTexts">
				<slot></slot>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	export default {
		props: {
			mode: {
				type: String
			},
			tabTexts: {
				type: Array,
				default () {
					return ["示例1", "示例2", "示例3", "示例4", "示例5", "示例6", "示例7", "示例8", "示例9"]
				}
			},
			title: {
				type: String,
				default () {
					return ''
				}
			},
		},
		data() {
			return {
				nowTab: 0
			};
		},
		methods: {
			checkTab(index) {
				this.nowTab = index
				this.sendTab()
			},
			swiper(value) {
				this.nowTab = value.detail.current
				this.sendTab()
			},
			sendTab(){
				this.$emit("getNowTab",this.nowTab)
			}
		}
	}
</script>

<style lang="scss">
	.swiper-view {
		margin-bottom: 20rpx;
		height: 100%;
		background-color: #fff;
		//padding: 10rpx;
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		overflow: hidden;
		//border: 2rpx blue red;

		.view-body {
			//border: 2rpx blue solid;
			box-sizing: border-box;
			
			flex-grow: 10;
			padding: 10rpx;
			margin: 0 10rpx 10rpx 10rpx;
			.item{
				box-sizing: border-box;
			}
		}

		.view-head-no_title {
			margin: 10rpx 0;
			padding: 10rpx;
			display: flex;
			flex-direction: row;
			position: relative;
			align-items: center;
			flex-grow: 0.5;
			width: auto;
			height: 36rpx;

			.view-tab-no_title {
				.scroll {
					display: flex;
					flex-direction: row;
					padding: 10rpx;
					box-sizing: border-box;

					.tab-item_select {
						margin: 10rpx 10rpx;
						font-size: 32rpx;
						color: $my-main-color;
						border-bottom: 4rpx $my-main-color solid;
						flex-shrink: 0;
						box-sizing: border-box;
					}

					.tab-item {
						margin: 10rpx 10rpx;
						font-size: 32rpx;
						flex-shrink: 0;
						box-sizing: border-box;
					}
				}
			}
		}

		.view-head {
			margin: 10rpx 0;
			padding: 10rpx;
			display: flex;
			flex-direction: row;
			position: relative;
			align-items: center;
			flex-grow: 0.5;
			width: auto;
			height: 36rpx;
			//box-shadow: 0rpx 6rpx 10rpx #dfdfdf;

			.view-title {
				font-size: 36rpx;
				font-weight: bold;
				color: #989898;
				margin-left: 10rpx;
			}

			.view-tab {
				position: absolute;
				display: flex;
				flex-direction: row;
				right: 10rpx;
				width: 70%;

				.scroll {
					display: flex;
					flex-direction: row;
					right: 10rpx;
					box-sizing: border-box;

					.tab-item_select {
						margin: 10rpx 10rpx;
						font-size: 32rpx;
						color: $my-main-color;
						border-bottom: 4rpx $my-main-color solid;
						flex-shrink: 0;
						box-sizing: border-box;
					}

					.tab-item {
						margin: 10rpx 10rpx;
						font-size: 32rpx;
						flex-shrink: 0;
						box-sizing: border-box;
					}
				}
			}
		}
	}
</style>
